package com.thread;

public class ThreadDemo3 {
    public static void main(String[] args) {
        new Thread(new MyRunnable01()).start();
        new Thread(new MyRunnable02()).start();


        Thread t3 = new Thread() {
            public void run(){
                for (int i = 0; i < 1000; i++) {
                    System.out.println("你是谁");
                }
            }
        };


//使用匿名内部类
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 1000; i++) {
//                    System.out.println("你是谁");
//                }
//            }
//        });

        //使用lambda表达式
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("你是谁");
            }
        });

//使用匿名内部类
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 1000; i++) {
//                    System.out.println("我是查水表的");
//                }
//            }
//        });


        //使用lambda表达式
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("我是查水表的");
            }
        });


        t1.start();
        t2.start();
    }
}

class MyRunnable01 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("你是谁");
        }
    }
}

class MyRunnable02 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println("我是查水表的");
        }
    }
}
